package com.study.talk.util;

import com.study.talk.app.App;

import org.greenrobot.eventbus.EventBus;

public class EventBusUtil {

    private static final EventBus event = EventBus.getDefault();

    public static void sendEvent(Object message, boolean isSticky) {
        if (isSticky) event.postSticky(message);
        else event.post(message);
    }

    public static void sendEvent(Object message) {
        event.post(message);
    }

    public static void sendEventDelayed(Object message, long time) {
        /*new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
           sendEvent(new OtherMessage(Constants.CONNECTION_SUCCESS));
        }).start();*/
        AppExecutor.getInstance().MAIN_HANDLER().postDelayed(() -> {
            sendEvent(new OtherMessage(Constants.CONNECTION_SUCCESS));
        },1000);
    }

    public static void registerEvent(Object obj) {
        event.register(obj);
    }

    public static void unregisterEvent(Object obj) {
        event.unregister(obj);
    }
}
